package com.wmh.baseservice.common.utils.Color;

import cn.hutool.core.img.BackgroundRemoval;
import cn.hutool.core.img.ImgUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;

public class ColorUtil {

    public static float colorAvgVal = 53.5f;

    //输入一张图片 返回该图片的均值色彩
    public static String getAvgRGB(URL url) {
        BufferedImage bi = ImgUtil.toBufferedImage(ImgUtil.scale(ImgUtil.read(url), 0.3f));
        String mainColor = BackgroundRemoval.getMainColor(bi);
        System.out.println(mainColor);
        return "";
    }

    //测试
    public static void main(String[] args) throws MalformedURLException {
        long time = System.currentTimeMillis();
        URL url = new URL("https://www.tdtye.com/files/vegetable_mall_file/groupGoodsM/7577445818513996/33d77ae95ddbb227e22233e7bd549474.jpeg");

        System.out.println(getAvgRGB(url));
        long endTime = System.currentTimeMillis(); //获取结束时间
        System.out.println(endTime - time);
    }
}
